package org.wf.game.fish;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class FishGame extends JFrame implements ActionListener{   
	private static final long serialVersionUID = 1L;
	JPanel a;//用于存放当前面板
	JButton simple,difficult,start;//简单、困难模式选择按钮，开始按钮
	PoolBuilder builder;//鱼池生成器
	Pool pool;//鱼池
	FishGame(String string)//游戏主窗口初始化
	{
		super(string);
		setSize(800, 480);
        setLocationRelativeTo(null);
        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(null);
        //初始化模式选择按钮
        simple=new JButton("简单模式");
        simple.setLocation(280,300);
        simple.setSize(200,30);
        difficult=new JButton("困难模式");
        difficult.setLocation(280,350);
        difficult.setSize(200,30);
        //加入监听器，属于类适配器模式
        simple.addActionListener(this);
        difficult.addActionListener(this);
        
        add(simple);
        add(difficult);
        //开始面板
        a=new init();
        add(a);
        setVisible(true);
      
	}
	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		
		if(arg0.getSource()==start)
		{//点击开始游戏
		start.setVisible(false);//开始按键消失
		Thread a=new Thread(){//用新线程来启动游戏，避免主线程进入阻塞；
			public void run() {
				pool.action();
			}
		};
		a.start();
		return;
		}
		else {
		if(arg0.getSource()==difficult)//选择困难模式
		{
			builder=new difficult_PoolBuilder();//绑定困难模式下的专属鱼池生成器
		}
		if(arg0.getSource()==simple)
		{
			builder=new simple_PoolBuilder();//绑定简单模式下的专属鱼池生成器
		}

		a.setVisible(false);//关闭开始界面面板
		simple.setVisible(false);//模式选择按键消失
		difficult.setVisible(false);
		pool=new Pool(builder);//创建鱼池
		add(pool);
		start=new JButton("开始游戏");//添加开始按键
		start.setLocation(280,300);
		start.setSize(200,30);
		start.addActionListener(this);//添加事件监听器
		add(start);
		
		}
	}
public static void main(String[] args) {new FishGame("捕鱼达人");}//主函数入口
}
class init extends JPanel{//开始界面面板
	init()
	{
		super();
		 setSize(800,480);
	     setLocation(0,0);
		 File bg = new File("images/welcome.jpg");//添加开始界面背景图
	        try {
	            bgImage = ImageIO.read(bg);
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	}
	BufferedImage bgImage;
	public void paint(Graphics g) {
	 g.drawImage(bgImage, 0, 0,800,480, null); 
	 g.setColor(Color.orange);
	 g.setFont(new Font("TimesRoman", Font.ITALIC, 80));
     g.drawString("Welcome FishGame", 40, 200);
	}
}
